﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <windows.h>        //注意头文件
#include <windowsx.h>
#include <QMouseEvent>
#include <QIcon>
#include <QDebug>
#include <QWebEngineProfile>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QProgressBar>
#include <QWebEngineHistory>

#include "tabwidget.h"
#include "statusbar.h"
#include "webview.h"
#include "customprogressbar.h"
#include "ui_mainwindow.h"
#include "attackwaring.h"
#include "messagewidget.h"
#include "feedbackwidget.h"
#include "settingwidget.h"
#include "bookmarkwidget.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class Explore;
class TabWidget;
class WebView;
class SettingWidget;

class MainWindow : public QWidget
{
    Q_OBJECT

public:


    MainWindow(Explore *explore, QWebEngineProfile *profile, QWidget *parent = nullptr);
    ~MainWindow();

    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;


    TabWidget* tabWidget(){return m_tabWidget;}
    Explore * explore(){return m_explore;}


    WebView *currentTab();

    URLLineEdit * urlLineWidget(){
        return ui->urlLineEditWidget;
    }

//    CustomProgressBar* progressBar(){return m_progressBar;};

    void handleBackBtn();
    void handleForwardBtn();
    void handleUrlNotSafe(QString url);

    MessageWidget* messageWidget(){return m_messageWidget;}
    FeedBackWidget * feedbackWidget(){return m_feedbackWidget;}
    SettingWidget * settingWidget(){return m_settingWidget;}
    BookMarkWidget * bookMarkWidget(){return m_bookMarkWidget;}

public slots:
    // 加载URL
    void handleUrlLoad(QUrl url);

    void handleLinkHover(const QString url);

    void mainWindowHandleLoadStart();
    void mainWindowHandleLoadProgress();
    void mainWindowHandleLoadFinish();

    void handleUrlStringLoad(QString url);
    void handleMarkIcon(bool s);

private slots:
    void on_minBtn_clicked();

    void on_maxOrNormalBtn_clicked();

    void on_closeWindowBtn_clicked();

    void handleUrlChanged(QUrl url);


    void on_refreshBtn_clicked();

    void on_backBtn_clicked();

    void on_forwardBtn_clicked();

    void on_homeBtn_clicked();

    void on_newTabBtn_clicked();

    void on_toolBtn_clicked();

    void on_menuBtn_clicked();

    void on_searchPageBtn_clicked();

    void on_paletteBtn_clicked();

    void on_userBtn_clicked();

private:
    Ui::MainWindow *ui;
    // 去掉系统边框自定义边框
    int boundaryWidth=4;
    // 鼠标点击的位置，用于计算移动窗口
    QPoint clickPoint;

    Explore *m_explore;
    QWebEngineProfile *m_profile;

    TabWidget* m_tabWidget;

    StatusBar *m_statusBar;

    AttackWaring *m_attackWaring;

    MessageWidget * m_messageWidget;
//    CustomProgressBar *m_progressBar;  // 不用

    FeedBackWidget *m_feedbackWidget;

    SettingWidget * m_settingWidget;

    BookMarkWidget *m_bookMarkWidget;

};
#endif // MAINWINDOW_H
